#include "confirmdialog.h"
#include "ui_confirmdialog.h"

ConfirmDialog::ConfirmDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfirmDialog)
{
    ui->setupUi(this);
    //setWindowModality(Qt::ApplicationModal);
}

ConfirmDialog::~ConfirmDialog()
{
    delete ui;
}

void ConfirmDialog::setUnlockPassword(QString pw)
{
    unlock = pw;
    ui->unlockedit->setText(pw);
    ui->unlockpasswd->setText(pw);
}

void ConfirmDialog::setIgnitionPassword(QString pw)
{
    ignition = pw;
    ui->ignitionedit->setText(pw);
    ui->ignitionpasswd->setText(pw);
}

void ConfirmDialog::on_unlockedit_textEdited(const QString &arg1)
{
    Q_UNUSED(arg1);
    if( ui->unlockedit->text()
     == ui->unlockpasswd->text())
    {
        ui->compare1->setEnabled(true);
        ui->compare1->setText(tr("Matched"));
    }
    else
    {
        ui->compare1->setEnabled(false);
        ui->compare1->setText(tr("Error"));
    }
}

void ConfirmDialog::on_ignitionedit_textEdited(const QString &arg1)
{
    Q_UNUSED(arg1);
    if( ui->ignitionedit->text()
     == ui->ignitionpasswd->text())
    {
        ui->compare2->setEnabled(true);
        ui->compare2->setText(tr("Matched"));
    }
    else
    {
        ui->compare2->setEnabled(false);
        ui->compare2->setText(tr("Error"));
    }
}

void ConfirmDialog::setPasswordFileName(QString fn)
{
    ui->filenameedit->setText(fn);
}

/*
void ConfirmDialog::on_buttonBox_clicked(QAbstractButton *button)
{
    if(ui->buttonBox->standardButton(button)
       == QDialogButtonBox::Ok)
        close();
    else
        qApp->exit(-1);
}
*/

void ConfirmDialog::closeEvent(QCloseEvent *event)
{
    Q_UNUSED(event);
    exit(-1);
}
